home *** CD-ROM | disk | FTP | other *** search
-
- /*
- DA Shell D/A -- Version 1.00 -- Oct 29, 1989
-
- Copyright (c) 1989 by Neal E. Trautman
-
- 'ShareWare' -- Please send $5 contribution to:
-
- Neal Trautman
- 1701 S.W. 42nd Street
- Fargo, ND 58103
-
- This is a D/A Shell.
- */
-
- #define date "\p10/29/89"
- #define version "\pv1.00"
-
- #define line1 "\p by Neal E. Trautman"
- #define line2 "\p'ShareWare'"
- #define line3 "\pPlease send $5 contribution to:"
- #define line4 "\pNeal Trautman"
- #define line5 "\p1701 S.W. 42nd Street"
- #define line6 "\pFargo, ND 58103"
- #define line7 version
- #define line8 date
-
- typedef enum {
- ABOUT = 1,
- ULINE,
- QUIT
- } Command;
-
- typedef unsigned long ulong;
-
- #define FAST register
-
- #define NULL 0L
- #define BUTTON_OFF 0
- #define BUTTON_ON 1
- #define BUTTON_DIM 255
-
- #define pstrlen(ps) (int)(ps[0])
- #define pcharcat(ps,ch) ps[++(ps[0])] = ch
-
- #define MENU 1
-
- #define CONTENT_H 100
- #define CONTENT_V 100
-
- #define INSET 4
- #define BUTTON_H 80
- #define BUTTON_V 20
- #define BOTTOM (INSET+CONTENT_V+INSET)
-
- #define WINDOWWIDTH (INSET+CONTENT_H+INSET)
- #define WINDOWHEIGHT (BOTTOM+INSET+BUTTON_V+INSET)
- #define WINDOWTOP 40
- #define WINDOWLEFT 2
-
- Boolean already_open = FALSE;
- DCtlPtr dce;
- Rect screenBounds;
- WindowPtr window;
- Rect rct;
- int linev,lineinc;
- int line_height;
- Str255 daname;
- ControlHandle aboutB = NULL;
- MenuHandle menu = NULL;
-
- static void pstrcpy(d, s)
- StringPtr d, s;
- {
- BlockMove(s, d, s[0] + 1);
- }
-
- static void pstrcat(d, s)
- StringPtr d, s;
- {
- BlockMove(s+1, d+(d[0])+1, s[0]);
- d[0] += s[0];
- }
-
- static int da_id(id)
- int id;
- {
- return((0xC000 + ((~dce->dCtlRefNum) << 5)) + id);
- }
-
- static void doline(line)
- StringPtr line;
- {
- MoveTo (rct.left + (rct.right - rct.left - StringWidth (line)) / 2, linev);
- DrawString (line);
- linev += lineinc;
- }
-
- static void drawabout(w)
- WindowPtr w;
- {
- Str255 str;
-
- linev = 24;
- lineinc = 14;
- rct = w->portRect;
- InsetRect (&rct, 4, 4);
- TextFont (systemFont);
- TextSize (12);
- pstrcpy(str,daname);
- pstrcat(str,line1);
- doline (str);
- TextFont (geneva);
- TextSize (9);
- doline ("\p");
- doline (line2);
- doline (line3);
- TextFace(bold);
- doline (line4);
- doline (line5);
- doline (line6);
- TextFace(0);
- MoveTo (rct.left, rct.bottom);
- DrawString (line7);
- MoveTo (rct.right - StringWidth (line8), rct.bottom);
- DrawString (line8);
- TextFace(0);
- }
-
- static void doAbout()
- {
- register WindowPtr w;
- EventRecord evt;
- Boolean done;
- int h,v;
- Rect r;
-
- InitCursor ();
- SetRect (&r, 0, 0, 240, 120);
- w = NewWindow (NULL, &r, "\p", FALSE, dBoxProc, -1L, FALSE, 0);
- SetPort (w);
- h = screenBounds.left + (((screenBounds.right - screenBounds.left) -
- (w->portRect.right - w->portRect.left)) / 2);
- v = screenBounds.top + (((screenBounds.bottom - screenBounds.top) -
- (w->portRect.bottom - w->portRect.top)) / 3);
- MoveWindow (w, h, v, FALSE);
- ShowWindow (w);
- /* drawabout (w); */
- done = FALSE;
- while (!done)
- {
- SystemTask();
- if (GetNextEvent (everyEvent, &evt))
- switch (evt.what)
- {
- case mouseDown:
- while (WaitMouseUp())
- ; /* and fall thru... */
- case mouseUp:
- case keyDown:
- case autoKey:
- done = TRUE;
- break;
- case updateEvt:
- if ((WindowPtr)(evt.message) == w)
- {
- SetPort (w);
- BeginUpdate (w);
- drawabout (w);
- EndUpdate (w);
- }
- break;
- }
- }
- DisposeWindow (w);
- FlushEvents (mDownMask+mUpMask+keyDownMask+keyUpMask+autoKeyMask,0);
- }
-
- static void flashbutton(ch)
- ControlHandle ch;
- {
- long ticks;
-
- HiliteControl(ch,BUTTON_ON);
- Delay(8L,&ticks);
- HiliteControl(ch,BUTTON_OFF);
- }
-
- static void doUpdate()
- {
- GrafPtr savePort;
- Rect r;
-
- GetPort(&savePort);
- SetPort(window);
-
- MoveTo(0,BOTTOM);
- LineTo(window->portRect.right,BOTTOM);
-
- TextFont(systemFont);
- TextSize(0);
- TextFace(bold | underline);
- MoveTo(INSET,BOTTOM / 2);
- DrawString(daname);
-
- /* Draw Window's Contents */
-
- SetPort(savePort);
- }
-
- static void doActivate(activate)
- Boolean activate;
- {
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(window);
- if (menu != NULL)
- {
- if (activate)
- InsertMenu(menu,0);
- else
- DeleteMenu(dce->dCtlMenu);
- DrawMenuBar();
- }
- InvalRect(&window->portRect);
- SetPort(savePort);
- }
-
- static void doCommand(option)
- Command option;
- {
- Boolean quit;
-
- quit = FALSE;
- switch (option)
- {
- case ABOUT:
- doAbout();
- break;
- case QUIT:
- quit = TRUE;
- break;
- }
- if (quit)
- CloseDriver(dce->dCtlRefNum);
- }
-
- static void doKey(c)
- char c;
- {
- switch (c)
- {
- case '\r':
- case '\03':
- case '`':
- case ' ':
- case 'a':
- case 'A':
- flashbutton(aboutB);
- doCommand(ABOUT);
- break;
- case 0x1B:
- case 'q':
- case 'Q':
- doCommand(QUIT);
- break;
- default :
- SysBeep(2);
- break;
- }
- }
-
- static void doMouse(p)
- Point p;
- {
- GrafPtr savePort;
- ControlHandle theControl;
-
- GetPort(&savePort);
- SetPort(window);
- GlobalToLocal(&p);
- FindControl(p, window, &theControl);
- if (theControl != NULL)
- {
- if (TrackControl(theControl, p, NULL ))
- {
- if (theControl == aboutB)
- {
- doCommand(ABOUT);
- }
- }
- }
- SetPort(savePort);
- }
-
- static void doEvent(evt)
- register EventRecord *evt;
- {
- GrafPtr savePort;
-
- switch (evt->what)
- {
- case updateEvt:
- GetPort(&savePort);
- SetPort(window);
- BeginUpdate(window);
- EraseRect(&window->portRect);
- DrawControls(window);
- doUpdate();
- EndUpdate(window);
- SetPort(savePort);
- break;
- case mouseDown:
- doMouse(evt->where);
- break;
- case activateEvt:
- doActivate((Boolean)(evt->modifiers & activeFlag));
- break;
- case keyDown:
- case autoKey:
- doKey((char)(evt->message & charCodeMask));
- break;
- }
- }
-
- static void doOpen(name)
- StringPtr name;
- {
- GrafPort myPort;
- GrafPtr savePort;
- FontInfo fInfo;
- Rect rect;
- int id,i;
- Str255 str;
- Handle h;
- char s2[8];
-
- dce->dCtlFlags |= dNeedLock|dNeedGoodBye;
- if (already_open)
- {
- SelectWindow(window);
- return;
- }
- already_open = TRUE;
-
- GetPort(&savePort);
-
- OpenPort (&myPort);
- screenBounds = myPort.portBits.bounds;
- ClosePort (&myPort);
-
- SetRect(&rect, WINDOWLEFT, WINDOWTOP, 100, 100);
- daname[0] = name[0]-1;
- BlockMove(name+2, daname+1, daname[0]);
- window = NewWindow( NULL, &rect, daname, FALSE, rDocProc, NULL, TRUE, NULL );
- if (window)
- {
- ((WindowPeek)window)->windowKind = dce->dCtlRefNum;
- dce->dCtlWindow = window;
-
- SetPort(window);
- TextFont(geneva);
- TextSize(9);
- GetFontInfo(&fInfo);
- line_height = fInfo.ascent+fInfo.descent+fInfo.leading;
-
- SizeWindow(window,WINDOWWIDTH,WINDOWHEIGHT,TRUE);
- ShowWindow(window);
- SelectWindow(window);
-
- SetRect(&rect, (WINDOWWIDTH / 2) - (BUTTON_H / 2), WINDOWHEIGHT-INSET-BUTTON_V,
- (WINDOWWIDTH / 2) + (BUTTON_H / 2), WINDOWHEIGHT-INSET);
- aboutB = NewControl( window, &rect, "\pAbout…", TRUE,
- BUTTON_OFF, BUTTON_OFF, BUTTON_ON, pushButProc, NULL );
-
- id = da_id(MENU);
- menu = NewMenu(id,daname);
- if (menu)
- {
- dce->dCtlMenu = id;
- pstrcpy(str,"\pAbout ");
- pstrcat(str,daname);
- pstrcat(str,"\p…/`");
- AppendMenu(menu,str);
- AppendMenu(menu,"\p(-");
- AppendMenu(menu,"\pQuit/Q");
- /* InsertMenu(menu,0); */
- }
- }
- SetPort(savePort);
- }
-
- static void doControl(code, parm)
- int code;
- int *parm;
- {
- switch(code)
- {
- case accEvent:
- doEvent(*((EventRecord **)parm));
- break;
- case accMenu:
- {
- switch(parm[1])
- {
- case ABOUT: /* About… */
- doCommand(ABOUT);
- break;
- case ULINE: /* (- */
- break;
- case QUIT: /* Quit */
- doCommand(QUIT);
- break;
- }
- HiliteMenu(0);
- break;
- }
- case accUndo:
- case accCut:
- case accCopy:
- case accPaste:
- case accClear:
- SysBeep(2);
- break;
- case accRun:
- break;
- case accCursor:
- break;
- }
- }
-
- static void doClose()
- {
- if (aboutB)
- DisposeControl(aboutB);
- if (window)
- {
- DisposeWindow(window);
- window = NULL;
- dce->dCtlWindow = NULL;
- }
- DeleteMenu(dce->dCtlMenu);
- dce->dCtlMenu = 0;
- DrawMenuBar();
- }
-
- main(p, d, n)
- cntrlParam *p;
- DCtlPtr d;
- int n;
- {
- if (d->dCtlStorage == NULL)
- {
- if (n == 0)
- {
- SysBeep(2);
- CloseDriver(d->dCtlRefNum);
- }
- return(0);
- }
- dce = d;
- dce->dCtlFlags &= ~dCtlEnable;
- switch (n)
- {
- case 0:
- doOpen(p->ioNamePtr);
- break;
- case 2:
- doControl(p->csCode, p->csParam);
- break;
- case 4:
- doClose();
- break;
- }
- dce->dCtlFlags |= dCtlEnable;
- return(0);
- }
-
-